package cn.stylefeng.guns.modular.transport.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.transport.entity.TransportStevedoreSignin;
import cn.stylefeng.guns.modular.transport.mapper.TransportStevedoreSigninMapper;
import cn.stylefeng.guns.modular.transport.model.params.TransportStevedoreSigninParam;
import cn.stylefeng.guns.modular.transport.model.result.TransportStevedoreSigninResult;
import  cn.stylefeng.guns.modular.transport.service.TransportStevedoreSigninService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 装卸签到表 服务实现类
 * </p>
 *
 * @author zhucx
 * @since 2023-11-04
 */
@Service
public class TransportStevedoreSigninServiceImpl extends ServiceImpl<TransportStevedoreSigninMapper, TransportStevedoreSignin> implements TransportStevedoreSigninService {

    @Override
    public void add(TransportStevedoreSigninParam param){
        TransportStevedoreSignin entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TransportStevedoreSigninParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TransportStevedoreSigninParam param){
        TransportStevedoreSignin oldEntity = getOldEntity(param);
        TransportStevedoreSignin newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TransportStevedoreSigninResult findBySpec(TransportStevedoreSigninParam param,Long operateId){
        return this.baseMapper.findBySpec(param,operateId);
    }

    @Override
    public List<TransportStevedoreSigninResult> findListBySpec(TransportStevedoreSigninParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TransportStevedoreSigninParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition,operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TransportStevedoreSigninParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TransportStevedoreSignin getOldEntity(TransportStevedoreSigninParam param) {
        return this.getById(getKey(param));
    }

    private TransportStevedoreSignin getEntity(TransportStevedoreSigninParam param) {
        TransportStevedoreSignin entity = new TransportStevedoreSignin();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public TransportStevedoreSigninResult findlastBySpec(TransportStevedoreSigninParam last, Long operateId) {
		return this.baseMapper.findlastBySpec(last,operateId);
	}

}
